﻿using System.Collections.Generic;
using System.Data;

namespace ncp.Business
{
    public class PictureInfoBll
    {
        /// <summary>
        /// 得到产品图片信息表
        /// </summary>
        public static DataTable GetPictureInfoTable(string p_Where, string p_Orderby, string pDataBase)
        {
            string sqlStr = "select * from bi_PictureInfo";
            if (!string.IsNullOrEmpty(p_Where))
                sqlStr += " where " + p_Where;
            if (!string.IsNullOrEmpty(p_Orderby))
                sqlStr += " order by " + p_Orderby;
            return CommonBll.GetdtList(sqlStr, pDataBase);
        }

        /// <summary>
        /// 得到记录数
        /// </summary>
        public static int GetPictureInfoCount(string pcWhere, string pDataBase)
        {
            string sqlStr = "select count(*) from bi_PictureInfo";
            if (!string.IsNullOrEmpty(pcWhere))
                sqlStr += " where " + pcWhere;
            return CommonBll.ReadInteger(sqlStr, pDataBase);
        }

        /// <summary>
        /// 修改产品图片信息
        /// </summary>
        public static int UpdatePictureInfo(Dictionary<string, object> dicProduct, string pDataBase)
        {
            string sqlStr = "UPDATE dbo.bi_PictureInfo " +
                            "SET Product_Id = '" + dicProduct["product_id"].ToString() + "',	" +
                            "Pic_Path = '" + dicProduct["pic_path"].ToString() + "', " +
                            "Pic_Note =  '" + dicProduct["pic_note"].ToString() + "', " +
                            "where Pic_Id='" + dicProduct["pic_id"].ToString() + "'";
            return CommonBll.ExecuteNonQuery(sqlStr, pDataBase);
        }

        /// <summary>
        /// 增加产品图片信息
        /// </summary>
        public static int InsertPictureInfo(Dictionary<string, object> dicProduct, string pDataBase)
        {
            string sqlStr = "INSERT INTO dbo.bi_PictureInfo (Product_Id, Pic_Path, Pic_Note) " +
                            "VALUES ('" + dicProduct["product_id"].ToString() + "', '" + dicProduct["pic_path"].ToString() + "', '" + dicProduct["pic_note"].ToString() + "')";
            return CommonBll.ExecuteQuery(sqlStr, pDataBase);
        }

        /// <summary>
        /// 删除产品图片
        /// </summary>
        public static int DeletePictureInfo(string Pic_Id, string pDataBase)
        {
            string sqlStr = "delete from bi_PictureInfo where Pic_Id in(" + Pic_Id + ")";
            return CommonBll.ExecuteNonQuery(sqlStr, pDataBase);
        }
    }
}
